
export class Player {
  x: number;
  y: number;
  offsetx: number = 0;
  offsety: number = 0;
  image: HTMLImageElement;

  constructor(x:number, y:number, image: HTMLImageElement) {
    this.x = x;
    this.y = y;
    this.image = image
  }

  setOffset(a: number, b: number) {
    this.offsetx = a
    this.offsety = b
  }

  refreshXY(pos:any) {
    this.x = pos.x - this.offsetx
    this.y = pos.y - this.offsety
  }

  isInsideImage(pos: any) {
    return (
      pos.x > this.x &&
      pos.x < this.x + this.image.width &&
      pos.y > this.y &&
      pos.y < this.y + this.image.height
    );
  }

  draw(ctx: any) {
    ctx.drawImage(
        this.image,
        this.x,
        this.y,
        this.image.width,
        this.image.height
      ); 
  }

}
